<template>
  <div ref="imageWrapper">
    <a-card title="查询条件" class="search">
      <!-- 查询区域 -->
      <div class="table-page-search-wrapper">
        <a-form-model ref="ruleForm" :model="queryParam" :rules="rules" layout="inline" @keyup.enter.native="onSearch">
          <a-row :gutter="24">
            <a-col :md="18" :sm="18">
              <a-form-model-item style="width: 500px" label="任务时间" prop="progressStatus">
                <a-select v-model="queryParam.progressStatus" placeholder="请选择状态">
                  <a-select-option value="0"> 全部 </a-select-option>
                  <a-select-option value="1">进行中</a-select-option>
                  <a-select-option value="2">已完成</a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
            <a-col :md="6" :sm="6">
              <span style="float: right" class="table-page-search-submitButtons">
                <a-button type="primary" @click="onSearch" icon="search">查询</a-button>
                <a-button @click="searchReset" icon="reload" class="clear_btn">清除条件</a-button>
                <a-button @click="GenerateResults" class="yellow_search_btn">一键成稿生成器</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form-model>
      </div>
    </a-card>
    <a-card style="margin-top: 20px">
      <a-table
        class="antableClass"
        ref="table"
        size="middle"
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange"
      >
        <template v-slot:progressStatus="text">
          <span v-if="text == 2">已完成</span>
          <span v-else>进行中</span>
        </template>
        <template v-slot:action="text, record">
          <a @click="handleDraftCheck(record)">查看</a>
          <a-divider type="vertical" />
          <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
            <a>删除</a>
          </a-popconfirm>
        </template>
      </a-table>
    </a-card>
    <CheckOrganModal ref="departModal" @ok="updateQueryParam" />
  </div>
</template>


<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { httpAction, getAction, postAction, deleteAction, putAction } from '@/api/manage'
import CheckOrganModal from '../../../znjkgl/zxzbfx/components/CheckOrganModal'
import columns from './columns'
export default {
  mixins: [JeecgListMixin],
  components: { CheckOrganModal },
  data() {
    return {
      queryParam: {
        progressStatus: '0',
      },
      url: {
        // 查询任务列数据
        list: '/sjmx/sjZxzyQuickDraft/queryPageLikeList',
        //删除某条任务
        delete: '/sjmx/sjZxzyQuickDraft/remove',
      },
      rules: {
        progressStatus: [{ required: true, message: '请选择', trigger: 'change' }],
        // arrayTime: [{ required: true, message: '请选择任期时间' }],
      },
      columns: columns(this),
      dataSource: [],
    }
  },
  methods: {
    // 清除条件
    searchReset() {
      this.queryParam = this.$options.data().queryParam
      this.dataSource = []
    },
    // 查看
    handleDraftCheck(record) {
      // 查看生成结果
      this.$emit('CheckGenerateResult', record)
    },
    // 打开生成结果组件
    GenerateResults() {
      this.$emit('GenerateResults')
    },
    //删除
    handleDelete(id) {
      deleteAction(this.url.delete, { id: id }).then((res) => {
        if (res.success) {
          this.$message.success(res.message)
          this.loadData()
        } else {
          this.$message.warning(res.message)
        }
      })
    },
    loadData(arg) {
      if (!this.url.list) {
        this.$message.error('请设置url.list属性!')
        return
      }
      // 加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1
      }
      var params = this.getQueryParams() // 查询条件
      this.loading = true
      getAction(this.url.list, params).then((res) => {
        if (res.success) {
          // update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          let data = res.result.records || res.result
          if (data.length == 0 && this.ipagination.current > 1) {
            this.ipagination.current--
            this.loadData()
          } else {
            this.dataSource = data
          }

          if (res.result.total) {
            this.ipagination.total = res.result.total
          } else {
            this.ipagination.total = 0
          }
          // update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
        }
        if (res.code === 510) {
          this.$message.warning(res.message)
        }
        this.loading = false
      })
    },
    openOrganModel() {
      this.$refs.departModal.edit()
    },
    updateQueryParam(data) {
      // console.log(data, 'daat')
      let str1 = ''
      let str2 = ''
      data.map((item) => {
        // TODO 账套～～～
        str1 += item.id + ','
        str2 += item.accName + ','
      })
      if (str1.length > 0) {
        str1 = str1.substr(0, str1.length - 1)
      }
      if (str2.length > 0) {
        str2 = str2.substr(0, str2.length - 1)
      }
      this.queryParam.ids = str1
      this.queryParam.accName = str2
      this.queryParam.extraId = str2
    },
    handleDatechange(dates) {
      this.queryParam.startTime = dates[0]
      this.queryParam.endTime = dates[1]
    },
    onSearch() {
      this.$refs.ruleForm.validate((value) => {
        if (value) {
          this.loadData(1)
        }
      })
    },
  },
}
</script>
<style lang="less" scoped>
@import '~@assets/less/tableTheme.less';
.ant-table-fixed-left .ant-table-thead > tr > th:last-child {
  border-top-right-radius: 0;
  background-color: red;
  padding: 0;
}
.yellow_search_btn {
  background-color: #ef9325;
  margin-left: 18px;
  color: white;
  font-size: 700;
}
</style>
